package com.longqinuo.mycarservice.adapter;



import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.longqinuo.mycarservice.R;
import com.longqinuo.mycarservice.entity.HotBrand;

import java.util.List;


/**
 * Created by zxw on 2016/5/24.
 */
public class HotBrandAdapter extends RecyclerView.Adapter<HotBrandAdapter.MyViewHolder>{
    private List<HotBrand> mList;
    private int itemLayout;
    private OnItemClickListener onItemClickListener;
    public HotBrandAdapter(List<HotBrand> list, int itemLayout) {
        this.mList = list;
        this.itemLayout = itemLayout;
    }
    public interface OnItemClickListener {
        void onItemClick(View itemView, int position);
    }
    public void setOnItemClickListener (OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(),itemLayout,null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        HotBrand h = mList.get(position);

        holder.logo.setImageResource(h.getLogo());
        holder.name.setText(h.getName());
        if (onItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(holder.itemView,position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);
            this.logo = (ImageView) itemView.findViewById(R.id.iv_logo_hot_brand);
            this.name = (TextView) itemView.findViewById(R.id.tv_name_hot_brand)
            ;
        }
        private ImageView logo;
        private TextView name;


    }
}

